<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
.m-hide {
	display: none;
	visibility: hidden;
	opacity: 0;
}

.table input[type="text"] {
	width: 100%;
}

.table>th {
	vertical-align: center;
	background-color: grey;
}

.td-item {
	width: 200px;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-header">
			<h1>新增/编辑关键字优惠券对应信息</h1>
		</div>
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<div class="widget-box widget-color-blue">
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>基本信息
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main">
								<form class="form-horizontal" id="validation-form" method="post"
									enctype="multipart/form-data">
									<input type="hidden" id="id"  name="id">
									<table id="baseinfo"
										class="table table-bordered table-striped table-hover table-condensed table-responsive table">
										<tr>
											<td class="td-item"><label for="keyword">关键字:</label></td>
											<td><input type="text" name="keyword" id="keyword"></td>
										</tr>
										<tr>
											<td class="td-item"><label for="channel">渠道名:</label></td>
											<td><input type="text" name="channel" id="channel"></td>
										</tr>
										<tr>
											<td class="td-item"><label for="fuel_coupon_id">优惠券ID(用
													","分割):</label></td>
											<td><input type="text" name="fuel_coupon_id"
												id="fuel_coupon_id"></td>
										</tr>
										<tr>
											<td class="td-item"><label for="coupon_type">用券类型:</label></td>
											<td><select name="coupon_type" id="coupon_type">
													<option value="1">加油券</option>
											</select></td>
										</tr>
									</table>
									<h3 style="color: red" id="errorMsg"></h3>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn  btn-inverse  no-border " onclick="doCancle()"
						id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>

					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button"
						onclick="doSave()">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>
	<%@ include file="/common/common-js.jsp"%>
	<script>
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;

		};

		var isEdit = false;
		var action = getQueryString('action');
		if (action == 'edit') {
			isEdit = true;
		}
		var id = getQueryString('id');

		if (isEdit) {
			 $.ajax({
					url: ctx+'/weixin/weixin_coupon_keyword_get.action',
					type: 'POST',
					async: false,
					dataType: 'json',
					data: {"id": id},
					success:function(json){
			            console.log("请求的商品tab", json);
			            if (json.status === 0) {
							var m = json.data;
							var keyword = m.keyword;
							var channel = m.channel;
							var fuel_coupon_id = m.fuel_coupon_id;
							var coupon_type = m.coupon_type;
							var id = m.id;

							$('#coupon_type').val(coupon_type);
							$('#fuel_coupon_id').val(fuel_coupon_id);
							$('#channel').val(channel);
							$('#keyword').val(keyword);
							$('#id').val(id);
						} else {
							alert('请求服务器错误,请刷新重试！！');
						}
					},
					error:function(){
						alert('请求服务器错误,请刷新重试！！');
					}
			  });
		}

		function doSave() {
			$("#btn-save").attr("disabled", "disabled");
			var $form = document.forms["validation-form"];
			// var data = $(document.forms["validation-form"]).serializeObject();
			// var url;
			if (isEdit) {
				$form.action = ctx
						+ "/weixin/weixin_coupon_keyword_update.action";
				$form.submit();
			} else {
				$form.action = ctx
						+ "/weixin/weixin_coupon_keyword_do_add.action";
				$form.submit();
			}
		}

		function doCancle() {
			parent.parent['__extdialog_active'].dialog('close');
		}
	</script>
</body>
</html>
